package cn.bookCity.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;





public class BeanFactory {
	
	public static Object getBean(String id) {
		try {
			//获取doc
			Document doc=new SAXReader().read(BeanFactory.class.getClassLoader().getResourceAsStream("beans.xml"));
			
			Element element=(Element)doc.selectSingleNode("//bean[@id='"+id+"']");
			
			//获取class
			String value=element.attributeValue("class");
			return Class.forName(value).newInstance();
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}
	public static void main(String[] args) {
		System.out.println(getBean("UserDao"));
	}

}
